package com.tangzhe.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * cookie和session
 */
public class CookieAndSessionServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie[] cookies = request.getCookies();
        for(Cookie cookie : cookies) {
            System.out.println(cookie.getName());
        }

        Cookie cookie = new Cookie("testCookie", "test");

        HttpSession session = request.getSession();
        String sessionId = session.getId();
        System.out.println("sessionId: " + sessionId);
    }
}
